//
//  MainViewController.swift
//  WeiBo
//
//  Created by 肖海东 on 15/12/13.
//  Copyright © 2015年 XiaoHaiDong. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        print(tabBar.classForCoder)
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        print(tabBar.classForCoder)
        
        // 添加子视图控制器
        addChildviewcontrollers()
        
    }

   private func addChildviewcontrollers() {
    
    addChildviewcontroller(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
    addChildviewcontroller(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
    addChildviewcontroller(DiscoverTableViewController(), title: "搜索", imageName: "tabbar_discover")
    addChildviewcontroller(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    

  
    }

    private func addChildviewcontroller(vc: UIViewController, title: String, imageName:String) {
        
        // 设置选中选项状态的图片和文字的颜色
        self.tabBar.tintColor = UIColor.orangeColor()
        
    let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
//        // 设置选中图片状态颜色
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        // 设置选中文字状态的颜色
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.greenColor()], forState: .Selected)
        
        self.addChildViewController(nav)
       
    
    }
    
}
